package com.hfplm.wyu.utils;

import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentTask;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCUserService;

public class SaveUtils {
	private static class SaveUtilsHolder {
		private static final SaveUtils INSTANCE = new SaveUtils();
	}

	private SaveUtils() {
	}

	public static final SaveUtils getInstance() {
		return SaveUtilsHolder.INSTANCE;
	}
	//cg_send_email
	public boolean sendEmailByTask(TCUserService userService,TCComponentTask component){
		try {
			Object [] objects = new Object[1];
			objects[0]=component;
			
			Object returnObj= userService.call("cg_send_email", objects);							
			if(returnObj.equals("0")){
				return true;
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	
	public boolean setPropertyByPass(TCUserService userService,TCComponent component,String PropertyName,String propertyValue){
		try {
			Object [] objects = new Object[3];
			objects[0]=component;
			objects[1]=PropertyName;
			objects[2]=propertyValue;
			Object returnObj= userService.call("cg_change_attr_bypass", objects);							
			if(returnObj.equals("0")){
				return true;
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public boolean setArrayPropertyByPass(TCUserService userService,TCComponent component,String PropertyName,String propertyValue){
		try {
			Object [] objects = new Object[3];
			objects[0]=component;
			objects[1]=PropertyName;
			objects[2]=propertyValue;
			Object returnObj= userService.call("cg_change_array_attr_bypass", objects);							
			if(returnObj.equals("0")){
				return true;
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public boolean setBOMLinePropertyByPass(TCUserService userService,TCComponent component,String PropertyName,String propertyValue){
		try {
			Object [] objects = new Object[3];
			objects[0]=component;
			objects[1]=PropertyName;
			objects[2]=propertyValue;
			Object returnObj= userService.call("cg_change_bomline_attr_bypass", objects);							
			if(returnObj.equals("0")){
				return true;
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public boolean CreateRelByPass(TCUserService userService,TCComponent sourcecomponent,TCComponent targetcomponent,String relation){
		try {
			Object [] objects = new Object[3];
			objects[0]=sourcecomponent;
			objects[1]=targetcomponent;
			objects[2]=relation;
			Object returnObj= userService.call("cg_create_rel_bypass", objects);							
			if(returnObj.equals("0")){
				return true;
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	public boolean DeleteRelByPass(TCUserService userService,TCComponent sourcecomponent,TCComponent targetcomponent,String relation){
		try {
			Object [] objects = new Object[3];
			objects[0]=sourcecomponent;
			objects[1]=targetcomponent;
			objects[2]=relation;
			Object returnObj= userService.call("cg_delete_rel_bypass", objects);							
			if(returnObj.equals("0")){
				return true;
			}
		} catch (TCException e) {
			e.printStackTrace();
		}
		return false;
	}
}
